package com.enjoyor.health.HGPT.core.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.enjoyor.health.HGPT.core.entity.WatchData;
import com.enjoyor.health.HGPT.core.mapper.WatchDataMapper;
import com.enjoyor.health.HGPT.core.service.IWatchDataService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author enjoyor
 * @since 2023-12-13
 */
@Service
public class WatchDataServiceImpl extends ServiceImpl<WatchDataMapper, WatchData> implements IWatchDataService {

    @Override
    public List<WatchData> getWatchDataList(String type, String openId, String deviceId) {
        LambdaQueryWrapper<WatchData> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(WatchData::getType, type)
                .eq(WatchData::getUserId, openId)
                .eq(WatchData::getDeviceId, deviceId)
                .gt(WatchData::getTime, LocalDate.now().minusDays(6).atStartOfDay())
                .orderByAsc(WatchData::getTime)
                //.last("LIMIT 100")
        ;
        return baseMapper.selectList(wrapper);
    }
}
